home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
ctools
/
print.c
< prev
Wrap
Text File
|
1985-12-24
|
6KB
|
217 lines
/* --------------------------------------------------- */
/* PRINT - Print a file with header to the printer */
/* M. Burton 04 July 1983 */
/* Written in Computer Innovations C86 */
/* --------------------------------------------------- */
/* Syntax: */
/* */
/* PRINT filename.typ - Print a file with line */
/* numbers. */
/* PRINT filename.typ /N - Print a file without */
/* line numbers. */
/* --------------------------------------------------- */
#include "stdio.h"
struct regval /* Register structure for INT */
{
int ax,bx,cx,dx,si,di,ds,es;
}
struct regval srv, rrv, trv, brv;
int mo, dy, yr;
int hr, mn, sc, hn;
char strng[256];
main(argc,argv)
int argc; /* Number of args in cmd line */
char *argv[]; /* Args in cmd line */
{
int *fd; /* File stream pointer */
int *cd; /* Printer stream pointer */
char *sp; /* filename.typ pointer */
int c; /* Loop variable */
int lineno=1; /* Line counter */
int pline=1; /* Line on page counter */
int page=1; /* Page counter */
char s[232]; /* Line buffer */
srv.ax = (0x2c << 8);
sysint(0x21,&srv,&brv); /* Get the time */
if (argc == 1)
{
fputs("Proper syntax: PRINT filename.typ </N>\007\n",stdout);
goto abort;
}
sp = argv[1];
while ((*sp = toupper(*sp)) != EOS) sp++;
fd = fopen(argv[1],"r");
if (fd == 0)
{
fputs(argv[1],stdout);
fputs(" not found\007\n");
goto abort;
}
cd = fopen("PRN:","w");
if (cd == 0)
{
fputs("Printer offline\007\n");
goto abort;
}
c = 1;
prthdr(page,cd,argv[1]);
while (c != EOS)
{
pline = 2;
while (pline < 57)
{
c = fgets(s,232,fd);
if (c == EOS) goto quit;
if (argc == 3)
{
if (strncmp(argv[2],"/n",2) == 0 || strncmp(argv[2],"/N",2) == 0)
{
fputs(s,cd);
}
}
else
{
iprnt(lineno,7," ");
fputs(strng,cd);
fputs(" ",cd);
fputs(s,cd);
}
lineno++;
pline++;
}
page++;
fputs("\n\014",cd);
prthdr(page,cd,argv[1]);
}
quit:
fputs(" \n\014",cd);
srv.ax = (0x2c << 8);
sysint(0x21,&srv,&trv); /* Get end time */
hr = (trv.cx >> 8) - (brv.cx >> 8);
if((mn = (trv.cx & 0xff) - (brv.cx & 0xff)) < 0)
{
hr--;
mn = mn + 60;
}
if((sc = (trv.dx >> 8) - (brv.dx >> 8)) < 0)
{
mn--;
sc = sc + 60;
if (mn < 0)
{
hr--;
mn = mn + 60;
}
}
fputs("Finished printing '",stdout);
fputs(argv[1],stdout);
fputs("'; ",stdout);
iprnt(--lineno,5," ");
fputs(strng,stdout);
fputs(" lines,",stdout);
iprnt(page,5," ");
fputs(strng,stdout);
fputs(" pages.\n",stdout);
fputs("Total print time ",stdout);
iprnt(hr,2,"0");
fputs(strng,stdout);
fputs(":",stdout);
iprnt(mn,2,"0");
fputs(strng,stdout);
fputs(":",stdout);
iprnt(sc,2,"0");
fputs(strng,stdout);
fputs("\n",stdout);
fclose(fd);
fclose(cd);
abort: ; /* Dummy line */
}
prthdr(p,cc,aa) /* Print the page header */
int p, cc, *aa;
{
srv.ax = (0x2a << 8);
sysint(0x21,&srv,&rrv);
mo = (rrv.dx >> 8);
dy = (rrv.dx & 0xff);
yr = rrv.cx;
srv.ax = (0x2c << 8);
sysint(0x21,&srv,&trv);
hr = (trv.cx >> 8);
mn = (trv.cx & 0xff);
sc = (trv.dx >> 8);
hn = (trv.dx & 0xff);
fputs("Listing of ",cc);
fputs(aa,cc);
fputs(" ",cc);
iprnt(mo,2,"0");
fputs(strng,cc);
fputs("-",cc);
iprnt(dy,2,"0");
fputs(strng,cc);
fputs("-",cc);
iprnt(yr,4,"0");
fputs(strng,cc);
fputs(" ",cc);
iprnt(hr,2,"0");
fputs(strng,cc);
fputs(":",cc);
iprnt(mn,2,"0");
fputs(strng,cc);
fputs(":",cc);
iprnt(sc,2,"0");
fputs(strng,cc);
fputs(".",cc);
iprnt(hn,2,"0");
fputs(strng,cc);
fputs(" Page ",cc);
iprnt(p,3," ");
fputs(strng,cc);
fputs("\n\n",cc);
}
iprnt(n,l,f) /* Print a decimal number */
int n,l;
char *f;
{
int i,j,sign,c;
if ((sign = n) < 0) n = -n;
i = 0;
do strng[i++] = n % 10 + '0';
while ((n /= 10) > 0);
if (sign < 0) strng[i++] = '-';
strng[i] = 0;
while (strlen(strng) < l)
{
strng[i++] = *f;
strng[i] = 0;
}
for (i=0, j=strlen(strng)-1; i<j; i++, j--)
{
c = strng[i];
strng[i] = strng[j];
strng[j] = c;
}
}
= x │ ε )dƒ┌Pï╞╚▄▐@Cfwî₧á▒∞'*eá█Qî╟!\^t}╞▌µΦ².Nbkì│╩╙╒⌠<S\^lîñ¡├ßε > ^ q ╟ ▌
+
A
T
}
ó
╞
τ
·
/<OnÆ¢ó┐▄D|àû»╕∞⌡6CZyåÅ╗┘⌡/Oiàº╤Θ7Smàí╝╧ΓQhkêº┬▀≤/Jgéƒ┐╘ε4LdzƬ─▄⌠
":PhÇû«╞≡8;=m}ìɺ⌐╠┌ DYzçº─╤&F_hk═ @DDD N